#!/bin/bash

# 查看服务状态
# Check Service Status

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

cd "$PROJECT_ROOT"

echo "📊 服务状态检查"
echo "================================"
echo ""

echo "🗄️  数据库服务："
docker compose -f docker-compose.databases.yml ps

echo ""
echo "🚀 应用服务："
docker compose -f docker-compose.services.yml ps

echo ""
echo "================================"
echo ""

# 检查服务健康状态
echo "🏥 健康检查："
echo ""

check_service() {
    local name=$1
    local url=$2

    if curl -s -o /dev/null -w "%{http_code}" "$url" | grep -q "200\|404\|307"; then
        echo "  ✅ $name - 运行正常"
    else
        echo "  ❌ $name - 无响应"
    fi
}

# 检查 API 服务
check_service "API 网关 (8000)" "http://localhost:8000/health" || true
check_service "爬虫服务 (8001)" "http://localhost:8001/health" || true
check_service "AI 服务 (8002)" "http://localhost:8002/health" || true
check_service "前端 Web (13000)" "http://localhost:13000" || true

echo ""
